/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2019/12/8 6:00 下午
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.example.spring.event.sender;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 消息发送者
 * </p>
 *
 * @author Yi
 * @version V1.0.0
 * @date 2019/12/8 6:00 下午
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人}  2019/12/8
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Component
@Setter
@Getter
public class EventPublisher implements ApplicationContextAware {

    private ApplicationContext ctx;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        setCtx(applicationContext);
    }

    public void sendMessage(ApplicationContextEvent event) {
        System.out.println("EventPublisher 开始发送" + event.getClass().getName());
        ctx.publishEvent(event);
    }
}
